import imgui
import imgui_font
using imgui

system.file.remove("./imgui.ini")

var monitor_w = get_monitor_width(0)
var monitor_h = get_monitor_height(0)
var app=window_application(get_monitor_width(0),get_monitor_height(0),"测试表格和各个控件的衔接")

# fonts
var font=add_font_extend_cn(imgui_font.source_han_sans, 32)
var large_font = add_font_extend_cn(imgui_font.source_han_sans, 54)
var tiny_font = add_font_extend_cn(imgui_font.source_han_sans,18)
set_font_scale(1.0)

# window size !!!!!!!！！注意！后续的你们所有的操作窗口按照这个标准来！！！！
var operating_window_size = vec2(to_integer(monitor_w/4*3),to_integer(monitor_h/8*7))
var operating_window_location = vec2(to_integer(monitor_w/4),to_integer(monitor_h/8))


# window status
var if_mywindow = true

#data cache 处理数据的地方
namespace data
    var textin=new string
    var info = new number
    var bm=new array
    var flag=false
    var view=false
    var view1=false
    var height=new string
    var weidht=new string
end    
# 渲染逻辑
while !app.is_closed()
    app.prepare()   
        style_color_light()
        push_font(font)
        if !data.flag
            input_text("请输入人数",data.textin,10)
            if button("确认输入")
                data.flag=true
            end
        end    
        if data.flag
            if !data.view1
                text("请输入第"+to_string(data.info+1)+"人的信息")
                input_text("请输入身高",data.height,10)
                input_text("请输入体重",data.weidht,10)
            end
            if data.info!=data.textin.to_number()
                if button("确认")
                    data.bm.push_back(data.weidht.to_number()/data.height.to_number()/data.height.to_number())
                    data.info+=1
                    if data.info==data.textin.to_number()
                        data.view1 = true
                    end    
                end
            else
                if button("显示结果")
                    data.view = true
                end   
            end
            if data.view
                # data.bm.push_back(data.weidht.to_number()/data.height.to_number()/data.height.to_number())
                foreach i in range(data.bm.size)
                    text("第"+to_string(i+1)+"个人的BMI:"+to_string(data.bm[i]))
                end
            end      
        end
        pop_font()
    app.render()
end